#include "Common.h"
#include "CentralCache.h"
class ThreadCache
{
public:
    //申请内存和释放内存
    void *Allocte(size_t size);
    void Deallocte(void *ptr, size_t size);

    //从中心缓存获取对象
    void *FetchFromCentralCache(size_t index, size_t size);

    //如果自由链表超过一定长度就要释放给中心缓存
    void ListTooLong(FreeList &freeList, size_t num, size_t size);

    ~ThreadCache()
    {
        for (int i = 0; i < NFREE_LIST; ++i) {
            if (!freeLists[i].Empty()) {
                ListTooLong(freeLists[i], freeLists[i].Num(), SizeClass::Index2Size(i));
            }
        }
    }
private:
    FreeList freeLists[NFREE_LIST];
};

static __thread ThreadCache *pThreadCache = nullptr;